package eureka.ui.me;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import eureka.domain.account.WebsiteUser;

/**
 * Servlet implementation class PersonalCenterServlet
 */
@WebServlet({ "/Me", "/Me/" })
public class PersonalCenterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PersonalCenterServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		
		WebsiteUser wuser = (WebsiteUser) session.getAttribute("user");
		
		if (wuser == null) {
			response.sendRedirect(request.getAttribute("contextPath") + "/Account/Login?redirect_url=" + URLEncoder.encode(request.getAttribute("contextPath") + "/Me", "UTF-8"));
			return;
		}
		
		request.getRequestDispatcher("/Me/personalcenter.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
